<?php
namespace app\index\controller;
use app\index\model\Users;
use app\index\model\UsersInfo;
class BaseIndex extends \think\Controller{
    public $userdata = false;
    public function __construct(){
        parent::__construct();
        //判断是否登录
        $session_id = \think\Session::get('uid');
        if($session_id >0){
            //查询数据库中是否有用户信息
            $users = new Users();
            $this->userdata = $users->where('id',$session_id)->find();
            if(!$this->userdata){
                return $this->error('非法操作，请重新登录！','index/Login/index');
            }
            $users_id = $this->userdata['id'];

            $users_info = new UsersInfo();
            $userdata = $users_info->where('users_id',$this->userdata['id'])->find();
            //向模板赋值
            $this->assign('userdata',$userdata);            
        }        
    }
}